package com.cskaoyan.wordmemorize.controller.app;

import com.cskaoyan.wordmemorize.auth.StpKit;
import com.cskaoyan.wordmemorize.common.result.Result;
import com.cskaoyan.wordmemorize.dto.app.DownLoadUserReviewDTO;
import com.cskaoyan.wordmemorize.request.PageRequest;
import com.cskaoyan.wordmemorize.request.UserReviewDataCommand;
import com.cskaoyan.wordmemorize.service.UserReviewService;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@RestController
@RequestMapping("/user/review")
public class UserVocRevController {
    @Autowired
    UserReviewService userReviewService;
    //添加用户的单词复习数据(参数为用户已选单词的id集合)
    @PostMapping("/voc")
    public Result addUserVocRev(@RequestBody List<Long> vocIds) {
        userReviewService.addUserRovRev(vocIds, StpKit.USER.getLoginIdAsLong());
        return Result.ok();
    }

    //下载用户的所有单词复习数据
    @GetMapping("/data")
    public Result<DownLoadUserReviewDTO> downloadUserVocRevData(PageRequest pageRequest) {
        DownLoadUserReviewDTO downLoadUserReviewDTO = userReviewService.downloadUserReviewData(pageRequest, StpKit.USER.getLoginIdAsLong());
        return Result.ok(downLoadUserReviewDTO);
    }


    //同步用户的复习数据
    @PostMapping("/data")
    public Result syncUserVocRevData(@RequestBody UserReviewDataCommand userReviewDataCommand) {
        userReviewService.synchronizeUserReviewData(userReviewDataCommand, StpKit.USER.getLoginIdAsLong());
        return Result.ok();
    }

}
